<script setup>
import {reactive,ref} from "vue";
import request from '@/api/request'
import {useRouter} from "vue-router"
let router = useRouter();

let orderReturns=ref({})
let formRef=ref()
let warehouse=ref([]);
let orderReturns1=ref([])

let isVisible=ref(false)
let title=ref("")
let data=ref({})

let page=ref({
    current:1,
    size:1000,
    total:0,
    records:[]
})

let toRemove=()=>{
    request({
        //查询客户
        url:"/orderRreturns/delete",
        method:"post",
        data:orderReturns1.value
    }).then(res=>{
    location()
    })
}
//修改
let toUpdate=async(row)=>{
    title.value="修改"
    isVisible.value=true;
    data.value=row;
    
    router.push("/sale/return/update");
}

let refTanle=()=>{
    isVisible.value=false;
    location();
}
//重置
let shuaxin=()=>{
    formRef.value.resetFields();
}
//新增
let toInsert=()=>{
    title.value="申请退货";
    isVisible.value=true;
    router.push("/sale/return/insert");
}

//选择框事件
let fuxuankuang=(a)=>{
    orderReturns1.value = a
}

let isUpdate=(row)=>{
    if(row=="申请中"){
        return true;
    }
    return false;
}

let location=()=>{
    
    request({
        //查询仓库
        url:"/warehouse",
        method:"get",
        params:{
            current:page.value.current,
            size:page.value.size
    }
    }).then(res=>{
        warehouse.value=res.data.date
    })

    request({
        //查询客户
        url:"orderRreturns",
        method:"get",
        params:{
            current:page.value.current,
            size:page.value.size,
            ...orderReturns.value
    }
    }).then(res=>{
        page.value=res.data
    })
}

location();
</script>

<template>
    <div>
        <el-card>
            <template #header>
                <el-form ref="formRef" inline :model="orderReturns" style="display: flex;justify-content: start;" class="card_wrap">
                    <el-form-item label="退货单号" prop="orderReturnsId" class="c_item">
                        <el-input v-model="orderReturns.orderReturnsId" class="sousuo" placeholder="请输入单号"></el-input>
                    </el-form-item>
                    <el-form-item label="报价单编码" prop="orderReturnsQuotationId" class="c_item">
                        <el-input v-model="orderReturns.orderReturnsQuotationId" class="sousuo" placeholder="请输入单号"></el-input>
                    </el-form-item>
                    <el-form-item label="退货仓库" prop="orderReturnsWarehouse" class="c_item">
                        <el-select class="sousuo" placeholder="仓库" v-model="orderReturns.orderReturnsWarehouse" @change="location">
                            <el-option label="全部" value="全部">
                                </el-option>
                            <el-option v-for="item in warehouse" :label="item.warehouseName" :value="item.warehouseId">
                                </el-option>
                        </el-select>
                    </el-form-item>
                    
                    
                    <el-form-item  class="c_item">
                        <template #default>
                             <el-button type="primary" @click="location">搜索</el-button>
                            <el-button type="info" :plain=true @click="shuaxin">重置</el-button><p></p>
                        </template>
                    </el-form-item>
                </el-form>

                <div style="margin: 20px 0px;">
                    <el-button @click="toInsert" type="primary" :plain="true">+添加</el-button>
                    <el-button type="danger" :plain=true @click="toRemove" style="border:0px" :disabled="!orderReturns1.length">删除</el-button>
                </div>

                <el-table :data="page.records" :header-cell-style="{ textAlign: 'center' }" :cell-style="{ textAlign: 'center' }"   @selection-change="fuxuankuang" show-overflow-tooltip>
                    <el-table-column type="selection" width="55"/>
                    <el-table-column type="expand">
                        <template  #default="props">
                            <div m="4" style="margin: 0 120px;padding: 10px 0;" v-if="props.row.orderReturnDetailsList">
                                <el-table :data="props.row.orderReturnDetailsList" :border="false" style="border:0px" :header-cell-style="{ textAlign: 'center' }" :cell-style="{ textAlign: 'center' }" show-overflow-tooltip>
                                    <el-table-column prop="orderReturnDetailId" label="退货明细码" width="100px;"/>
                                    <el-table-column prop="orderReturnDetailOrderReturnsId" label="退货单编码" width="100px;"/>
                                    <el-table-column prop="orderReturnDetailProductsId" label="产品编码" width="100px;"/>
                                    <el-table-column prop="orderReturnDetailQuoteDetailsId" label="报价详情编码" width="110px;"/>
                                    <el-table-column prop="orderReturnDetailShippingDetailsId" label="发货详情编码" width="110px;"/>
                                    <el-table-column prop="orderReturnDetailOutboundReturns" label="已出库退货数量" width="130px;"/>
                                    <el-table-column prop="orderReturnDetailOutboundReturnWeight" label="已出库退货重量" width="130px;"/>
                                    <el-table-column prop="orderReturnDetailNoOutboundReturns" label="未出库退货数量" width="130px;"/>
                                    <el-table-column prop="orderReturnDetailNoOutboundReturnWeight" label="未出库退货重量" width="140px;"/>
                                    <el-table-column prop="orderReturnDetailNoTheTotalSalePrice" label="已出库总价" width="100px;"/>
                                    <el-table-column prop="orderReturnDetailTheTotalSalePrice" label="未出库退货总价" width="100px;"/>
                                </el-table>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="orderReturnsId" label="退货编码" width="80px;" />
                    <el-table-column prop="orderReturnsQuotationId" label="报价单编码" width="100px;"/>
                    <el-table-column prop="orderReturnsShipmentHistoryId" label="发货单编码" width="100px;"/>
                    <el-table-column prop="orderReturnsApplicationTimeline" label="申请退货时间" width="110px;"/>
                    <el-table-column prop="orderReturnsCause" label="退货原因" width="100px;" />
                    <el-table-column prop="orderReturnsOutboundQuantity" label="已出库退货数量" width="130px;"/>
                    <el-table-column prop="orderReturnsOutboundWeight" label="已出库退货重量" width="130px;"/>
                    <el-table-column prop="orderReturnsTheOutboundAmount" label="已出库退货总金额" width="140px;"/>
                    <el-table-column prop="orderReturnsTotalQuantity" label="退货总数量" width="100px;"/>
                    <el-table-column prop="orderReturnsTotalWeight" label="退货总重量" width="100px;"/>
                    <el-table-column prop="orderReturnsState" label="状态" width="80px;"/>
                    <el-table-column prop="nickname" label="经办人" width="100px;"/>
                    <el-table-column label="操作" width="120px;" fixed="right">
                        <template #default="scope">
                            <el-button type="primary" v-if="isUpdate(scope.row.orderReturnsState)" @click="toUpdate(scope.row)" :row="scope.row">修改</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <el-dialog
                    :title="title"
                    v-model="isVisible"
                    :destroy-on-close="true"
                    width="60%">
                    <router-view @ref-table="refTanle" :data="data">
                    </router-view>
                </el-dialog>
            </template>
            
        </el-card>
       
    </div>
</template>

<style scoped>
.sousuo{
    width:200px;
    /* margin-right: 100px; */
}
.card_wrap {
    width: 98%;
    display: flex;
    flex-wrap: wrap;
    justify-content:flex-start;
}
.c_item{
    flex:1;
    margin:0px 5px 15px 0;
    width: calc((100%-10px)/3); 
    min-width:calc((100% - 10px)/3);
    max-width:calc((100% - 10px)/3);
    &:nth-child(3n){
        margin-right:0;
    }
}
[m='4'] :deep(.el-table){
    --el-table-border-color: transparent
}
:deep(.el-tooltip):hover{
    cursor: pointer;
}
</style>